home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / recode.lha / recode-3.2.4 / asciflat.c < prev    next >
C/C++ Source or Header  |  1992-09-25  |  4KB  |  142 lines

  1. /* Conversion of files between different charsets and usages.
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.    Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful, but
  11.    WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #define STEP    ascii_flat
  21. #include <stdio.h>
  22. #include "common.h"
  23.  
  24. /* Previous obsolete lex code:
  25.  
  26. \n            { ECHO; }
  27.  
  28. \000            { output ('^'); output ('@'); }
  29. \001            { output ('^'); output ('A'); }
  30. \002            { output ('^'); output ('B'); }
  31. \003            { output ('^'); output ('C'); }
  32. \004            { output ('^'); output ('D'); }
  33. \005            { output ('^'); output ('E'); }
  34. \006            { output ('^'); output ('F'); }
  35. \007            { output ('\\'); output ('a'); }
  36. \010            { output ('\\'); output ('b'); }
  37. \011            { output ('\\'); output ('t'); }
  38. \012            { output ('\\'); output ('n'); }
  39. \013            { output ('^'); output ('K'); }
  40. \014            { output ('^'); output ('L'); }
  41. \015            { output ('^'); output ('M'); }
  42. \016            { output ('^'); output ('N'); }
  43. \017            { output ('^'); output ('O'); }
  44. \020            { output ('^'); output ('P'); }
  45. \021            { output ('^'); output ('Q'); }
  46. \022            { output ('^'); output ('R'); }
  47. \023            { output ('^'); output ('S'); }
  48. \024            { output ('^'); output ('T'); }
  49. \025            { output ('^'); output ('U'); }
  50. \026            { output ('^'); output ('V'); }
  51. \027            { output ('^'); output ('W'); }
  52. \030            { output ('^'); output ('X'); }
  53. \031            { output ('^'); output ('Y'); }
  54. \032            { output ('^'); output ('Z'); }
  55. \033            { output ('^'); output ('['); }
  56. \034            { output ('^'); output ('\\'); }
  57. \035            { output ('^'); output (']'); }
  58. \036            { output ('^'); output ('^'); }
  59. \037            { output ('^'); output ('_'); }
  60.  
  61. \177            { output ('D'); output ('E'); output ('L'); }
  62.  
  63. ['`^",_]\b.        { output (yytext[2]); }
  64. .\b['`^",_]        { output (yytext[0]); }
  65.  
  66. */
  67.  
  68. void
  69. STEP (FILE *input_file, FILE *output_file)
  70. {
  71.   int input_char;        /* current character */
  72.   int temp_char;        /* look ahead character */
  73.  
  74.   input_char = getc (input_file);
  75.   while (1)
  76.     switch (input_char)
  77.       {
  78.       case EOF:
  79.     return;
  80.  
  81.       case '\n':
  82.     putc ('\n', output_file);
  83.     input_char = getc (input_file);
  84.     break;
  85.  
  86.       case '\b':
  87.     input_char = getc (input_file);
  88.     switch (input_char)
  89.       {
  90.       case EOF:
  91.         putc ('^', output_file);
  92.         putc ('H', output_file);
  93.         return;
  94.  
  95.       case '\'':
  96.       case '`':
  97.       case '^':
  98.       case '"':
  99.       case ',':
  100.       case '_':
  101.         input_char = getc (input_file);
  102.         break;
  103.  
  104.       default:
  105.         putc ('^', output_file);
  106.         putc ('H', output_file);
  107.       }
  108.     break;
  109.  
  110.       case '\'':
  111.       case '`':
  112.       case '^':
  113.       case '"':
  114.       case ',':
  115.       case '_':
  116.     temp_char = getc (input_file);
  117.     if (temp_char == '\b')
  118.       input_char = getc (input_file);
  119.     else
  120.       {
  121.         putc (input_char, output_file);
  122.         input_char = temp_char;
  123.       }
  124.     break;
  125.  
  126.       default:
  127.     if (input_char & 0200)
  128.       {
  129.         putc ('M', output_file);
  130.         putc ('-', output_file);
  131.         input_char &= 0177;
  132.       }
  133.     if (input_char < ' ' || input_char == 0177)
  134.       {
  135.         putc ('^', output_file);
  136.         input_char ^= 0100;
  137.       }
  138.     putc (input_char, output_file);
  139.     input_char = getc (input_file);
  140.       }
  141. }
  142.